package com.example.exam.controller;

import com.example.exam.entity.Role;
import com.example.exam.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * (Role)表控制层
 *
 * @author makejava
 * @since 2021-09-04 15:02:45
 */
@RestController
@RequestMapping("role")
public class RoleController {
    /**
     * 服务对象
     */
    @Autowired
    private RoleService roleService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Role selectOne(Integer id) {
        return this.roleService.queryById(id);
    }


    //姚贾涛
    @RequestMapping("/selectAll")
    public Map<String, Object> selectAll(Integer page, Integer limit, String roleName) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("data", roleService.selectAll2(page, limit, roleName));
        map.put("count", roleService.getroleCount2(roleName));
        return map;
    }

    @RequestMapping("/update")
    public boolean update(Role role) {
        return roleService.update2(role);
    }

    @RequestMapping("/delete")
    public boolean delete(@RequestParam("bids[]") int bids[]) {
        return roleService.delete2(bids);
    }

}